<template>
	<view class="settingIndex">
		<view class="tips mt-24">用户信息</view>
		<view class="template">
			<view class="wrap">
				<view class="item " style="border: none;">
					<view class="label">个人资料</view>
					<view class="value"  @click="toUrl('setUp')">
						<view class="valueText">{{userInfo.realName}}</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="tips mt-24 mtop-64">账户与安全</view>
		<view class="template">
			<view class="wrap">
				<view class="item">
					<view class="label">手机号</view>
					<view class="value"  @click="toUrl('phone')">
						<view class="valueText">{{userInfo.phone}}</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<view class="wrap">
				<view class="item">
					<view class="label">微信号</view>
					<view class="value" @click="toUrl('wxNumber')">
						<view class="valueText">{{userInfo.wxNumber}}</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<!-- 审核期间显示此按钮 -->
			<view v-if="!bankSwitch" class="wrap">
				<view @click="openPhone" class="item">
					<view class="label">账号注销</view>
					<view class="value">
						<view class="valueText"></view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="template" style="margin-top: 24rpx;">
			<view class="wrap">
				<view class="item" @click="toUrl('loginPass')">
					<view class="label">登录密码</view>
					<view class="value">
						<view class="valueText">修改</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<view class="wrap">
				<view class="item">
					<view class="label">实名认证</view>
					<view class="value">
						<view class="valueText">{{userInfo.realName}}</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<view class="wrap">
				<view class="item">
					<view class="label">银行卡</view>
					<view class="value"  @click="toUrl('bankCard')">
						<view class="valueText" v-if="userInfo.bankCardNum > 0">{{userInfo.bankCardNum}}张</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<view class="wrap">
				<view class="item">
					<view class="label">支付密码</view>
					<view class="value"  @click="toUrl('payPass')">
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<view class="wrap">
				<view class="item">
					<view class="label">关于灰耳朵陪宠</view>
					<view class="value"  @click="toUrl('pet')">
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<!-- #ifdef APP -->
		<view class="btn mtop-64" @click="otherLogin()">登录其他账号</view>
		<!-- #endif -->
		<view class="btn" style="margin-top: 32rpx;color: #1B2120;" @click="logOut()">退出登录</view>
		
		<uni-popup ref="popupRef" type="bottom" class="popup">
			<view class="popu_box">
				<view class="popuBtn" @click="toUrl('editPass')">修改支付密码</view>
				<view class="popuBtn" @click="toUrl('forgetPass')">忘记支付密码</view>
				<view class="line"></view>
				<view class="popuBtn" @click="closePopup()">取消</view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup lang="ts">
	import { onShow } from '@dcloudio/uni-app'
	import { useUserStoreToRefs } from '@/store/useUserStore'
	import { logOut, updateUserInfo }from '@/hooks/useLogin'
	import { ref } from 'vue'
	import {useStudioStoreToRefs} from "@/store/useStudioStore";
	import { accredit } from '@/hooks/useAppPermission/index';
	import { useConfigStoreToRefs } from '@/store/useConfigStore'
	const { bankSwitch } = useConfigStoreToRefs()
	let {workSpace} = useStudioStoreToRefs()
	const { userInfo } = useUserStoreToRefs()
	const  popupRef = ref()
	onShow((option) => {
		updateUserInfo()
	})
	const openPhone = async ()=>{
		uni.navigateTo({
			url:'/pages/setting/cancelAccount/index'
		})
		// const status = await accredit('CALL_PHONE')
		// if (status != 1) return
		// uni.showModal({
		// 	title:'提示',
		// 	content: '前往联系客服提交注销账号申请',
		// 	confirmText: '确定呼叫'
		// }).then((e)=>{
		// 	if(e.confirm){
		// 		uni.makePhoneCall({
		// 			phoneNumber: '400-154-1313'
		// 		})
		// 	}
		// })
	}
	const closePopup = () => {
		popupRef.value.close()
	}
	
	const otherLogin = () => {
		uni.navigateTo({
			url: `/pages/setting/changeAccountNumber/index`
		})
	}
	
	const toUrl = (type: string) => {
		if(type == 'pet'){
			uni.navigateTo({
				url: `/pages/setting/about/index`
			})
		}else if(type == 'setUp'){
			uni.navigateTo({
				url: `/pages/setting/setUp/index`
			})
		}else if(type == 'phone'){
			uni.navigateTo({
				url: `/pages/setting/phone/index`
			})
		}else if( type == 'bankCard'){
			uni.navigateTo({
				url: `/pages/myStudio/studio/bankCardManagement/index`
			})
		}else if(type == 'payPass'){
			if(userInfo.value.paymentPassword == ''){
				uni.navigateTo({
					url: `/pages/myStudio/studio/setPaymentPassword/index`
				})
			}else{
				popupRef.value.open()
			}
		}else if(type == 'wxNumber'){
			uni.navigateTo({
				url: `/pages/setting/modifyName/index?type=wxNumber`
			})
		}else if(type == 'editPass'){
			uni.navigateTo({
				url: `/pages/myStudio/studio/changePaymentPassword/index`
			})
			closePopup()
		}else if(type == 'forgetPass'){
			uni.navigateTo({
				url: `/pages/myStudio/studio/verifyPhoneNumber/index`
			})
			closePopup()
		}else if(type == 'loginPass'){
			uni.navigateTo({
				url: `/pages/login/verifyPhone?phone=${userInfo.value.phone}&userId=${userInfo.value.id}`
			})
		}
	}
</script>

<style lang="scss" scoped>
	.popu_box{
		background-color: #fff;
		// margin-bottom: -34px;
		text-align: center;
		font-size: 30rpx;
		color: #1A1A1A;
		border-radius: 36rpx 36rpx 0;
		.popuBtn{
			padding: 32rpx 0;
			box-sizing: border-box;
			border-bottom: 1rpx solid #E6E6E6;
			&:last-child{
				border-bottom:none;
			}
		}
		.line{
			height: 20rpx;
			background-color: #f8f8f8;
			width: 100%;
		}
	}
	.template{
		padding: 0 32rpx ;
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		.wrap{
			border-radius: 0 !important;
			&:last-child .item{
				border: none !important;
			}
		}
	}
	.settingIndex{
		// height: 100%;
		background-color: #F9F6F6;
		/* #ifdef APP */
		padding: 48rpx 32rpx 140rpx;
		/* #endif */
		/* #ifndef APP-PLUS */
		padding: 48rpx 32rpx 110rpx;
		/* #endif */
		box-sizing: border-box;
		.mt-24{
			margin-bottom: 24rpx;
			padding-left: 32rpx;
			box-sizing: border-box;
		}
		.mtop-64{
			margin-top: 64rpx;
		}
		.tips{
			font-size: 26rpx;
			color: #5C5E5E;
			font-weight: bold;
		}
		.wrap{
			// padding: 0 32rpx ;
			// box-sizing: border-box;
			// background-color: #fff;
			// border-radius: 24rpx 24rpx 24rpx 24rpx;
			.item{
				font-size: 32rpx;
				color: #1A1A1A;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 1rpx solid #E6E6E6;
				padding: 40rpx 0;
				box-sizing: border-box;
				// &:last-child{
				// 	border: none;
				// }
				.label{
					width: 250rpx;
				}
				.value{
					width: calc(100% - 250rpx);
					display: flex;
					align-items: center;
					justify-content: flex-end;
					color: #808080;
					font-size: 28rpx;
					.uniIcon{
						width: 60rpx;
						text-align: right;
					}
				}
				.valueText{
					color: #808080;
					font-size: 28rpx;
					word-break: break-all !important;
					margin-bottom: 4rpx;
					.pic{
						width: 100rpx;
						height: 100rpx;
						background: linear-gradient( 90deg, #FFA6BC 0%, #FFA3A3 100%);
						border-radius: 50%;
					}
				}
			}
		}
		.btn{
			background: #fff;
			border-radius: 62rpx 62rpx 62rpx 62rpx;
			text-align: center;
			line-height: 88rpx;
			font-size: 28rpx;
			color: #FF6084;
			letter-spacing: 2rpx;
			font-weight: bold;
		}
	}
</style>